package dao

import (
	"blog_server/internal/model/entity"
	"blog_server/internal/model/request"
	"blog_server/pkg/app"
)

func (d Dao) CreateTag(param *request.TagRequest) error {
	tag := entity.Tag{TagName: param.TagName, TagDes: param.Des}
	return tag.Create(d.engine)
}

func (d Dao) CountTags() (uint, error) {
	var tag entity.Tag
	return tag.Count(d.engine)
}

func (d Dao) GetTagsByPagination(page, pageSize int) ([]entity.Tag, error) {
	tag := entity.Tag{}
	return tag.GetByPagination(d.engine, app.GetPageOffset(page, pageSize), pageSize)
}

func (d Dao) UpdateTag(tag *entity.Tag) error {
	return tag.Update(d.engine)
}

func (d Dao) DeleteTag(tag *entity.Tag) error {
	return tag.Delete(d.engine)
}

func (d Dao) GetTagsBySearchText(text string) ([]entity.Tag, error) {
	var tag entity.Tag
	return tag.GetBySearchText(d.engine, text)
}

func (d Dao) GetAllTags() ([]entity.Tag, error) {
	var tag entity.Tag
	return tag.GetAll(d.engine)
}
